﻿using UnityEngine;
using System.Collections;

public class CameraZoom : MonoBehaviour {
	
	// Using camera
	// Lens: 35 mm
	// Vertical: 24 mm
	// Horizontal: 36 mm
	// => Diagonal: 43.3 mm
	
	public Texture2D  btnZoom;
	private float alpha = 60.0f;	// angle of view in radian
	private float f = 50.0f; 		// focal length: 12 - 200 mm
	private float d = 43.3f; 		// diagonal from lens 35 mm about 43.3 mm
		
	void OnGUI() {
	
		GUI.DrawTexture(new Rect(0, 0, 64, 64), btnZoom);
		GUI.Label(new Rect(70, 0, 300, 25), "Lens: " + f + " mm");
						
		// Use slider to zoom
		f = GUI.HorizontalSlider(new Rect(70, 30, 250, 30), f, 12, 200);
		alpha = 2 * Mathf.Atan(d / (2 * f));
		// convert alpha from radian to degree
		camera.fieldOfView = alpha * 180 / Mathf.PI;
	
	}
}
